import React from "react";
class Index extends React.Component{
    constructor(props){
        console.log(props);
        super();
        console.log("生命周期函数-constructor");

        this.state={
            title:"hello"
        }
    }
    static getDerivedStateFromProps(props,state){
        console.log("生命周期函数getDerivedStateFromProps");
        console.log(props);
        console.log(state);

        return props;

    }
    componentDidMount(){
        console.log("生命周期函数-componentDidMount");

    }
    shouldComponentUpdate(props){
        console.log("生命周期函数-shouldComponentUpdate");

        return props;
    }
    update=()=>{

        this.setState({title:"你好"})
    }
    getSnapshotBeforeUpdate(preprops,prestate){

        console.log("生命周期函数-getSnapshotBeforeUpdate");
        console.log(prestate);

        return preprops;
    }
    componentDidUpdate(){
        console.log("生命周期函数-componentDidUpdate");
    }
    componentWillUnmount(){
        console.log("生命周期函数-componentWillUnmount");
    }
     render(){
       
        console.log("生命周期函数-render");
        return <div>
            {this.state.title}
            生命周期函数

            <button onClick={this.update}>修改</button>
        </div>
    }
}
export default Index;